From e6ad28f6948b5497981b43ce16a5e2766bd810cc Mon Sep 17 00:00:00 2001 From: Debian Science Maintainers Date: Tue, 9 Dec 2025 11:19:37 +0000 Subject: [PATCH] Use fixed seeds for reproducible pseudorandomness Author: Rebecca N. Palmer Forwarded: no Gbp-Pq: Name fix_random_seeds.patch --- .../comparison/comparison_with_r.rst | 1 + doc/source/user_guide/10min.rst | 10 ++++ doc/source/user_guide/advanced.rst | 1 + doc/source/user_guide/style.ipynb | 50 +++++++++++++++++-- doc/source/user_guide/visualization.rst | 1 + pandas/plotting/_core.py | 4 ++ pandas/plotting/_misc.py | 4 ++ 7 files changed, 67 insertions(+), 4 deletions(-) diff --git a/doc/source/getting_started/comparison/comparison_with_r.rst b/doc/source/getting_started/comparison/comparison_with_r.rst index a6cfcd46..836e3669 100644 --- a/doc/source/getting_started/comparison/comparison_with_r.rst +++ b/doc/source/getting_started/comparison/comparison_with_r.rst @@ -237,6 +237,7 @@ In pandas we may use :meth:`~pandas.pivot_table` method to handle this: import random import string + random.seed(123456) # for reproducibility baseball = pd.DataFrame( { diff --git a/doc/source/user_guide/10min.rst b/doc/source/user_guide/10min.rst index c8e67710..2ea1a6e5 100644 --- a/doc/source/user_guide/10min.rst +++ b/doc/source/user_guide/10min.rst @@ -700,6 +700,11 @@ We use the standard convention for referencing the matplotlib API: The ``plt.close`` method is used to `close `__ a figure window: +.. ipython:: python + :suppress: + + np.random.seed(123456) # for reproducibility + .. ipython:: python ts = pd.Series(np.random.randn(1000), index=pd.date_range("1/1/2000", periods=1000)) @@ -716,6 +721,11 @@ The ``plt.close`` method is used to `close >> np.random.seed(1234) >>> import itertools >>> tuples = [t for t in itertools.product(range(1000), range(4))] >>> index = pd.MultiIndex.from_tuples(tuples, names=['lvl0', 'lvl1']) @@ -1328,6 +1329,7 @@ class PlotAccessor(PandasObject): .. plot:: :context: close-figs + >>> np.random.seed(1234) >>> data = np.random.randn(25, 4) >>> df = pd.DataFrame(data, columns=list('ABCD')) >>> ax = df.plot.box() @@ -1392,6 +1394,7 @@ class PlotAccessor(PandasObject): .. plot:: :context: close-figs + >>> np.random.seed(1234) >>> df = pd.DataFrame(np.random.randint(1, 7, 6000), columns=['one']) >>> df['two'] = df['one'] + np.random.randint(1, 7, 6000) >>> ax = df.plot.hist(bins=12, alpha=0.5) @@ -1811,6 +1814,7 @@ class PlotAccessor(PandasObject): .. plot:: :context: close-figs + >>> np.random.seed(1234) >>> n = 10000 >>> df = pd.DataFrame({'x': np.random.randn(n), ... 'y': np.random.randn(n)}) diff --git a/pandas/plotting/_misc.py b/pandas/plotting/_misc.py index 18db460d..4be948a1 100644 --- a/pandas/plotting/_misc.py +++ b/pandas/plotting/_misc.py @@ -204,6 +204,7 @@ def scatter_matrix( .. plot:: :context: close-figs + >>> np.random.seed(1234) >>> df = pd.DataFrame(np.random.randn(1000, 4), columns=['A','B','C','D']) >>> pd.plotting.scatter_matrix(df, alpha=0.2) array([[, , @@ -438,6 +439,8 @@ def bootstrap_plot( .. plot:: :context: close-figs + >>> np.random.seed(1234) + >>> random.seed(1234) # for reproducibility >>> s = pd.Series(np.random.uniform(size=100)) >>> pd.plotting.bootstrap_plot(s) # doctest: +SKIP
@@ -597,6 +600,7 @@ def autocorrelation_plot(series: Series, ax: Axes | None = None, **kwargs) -> Ax .. plot:: :context: close-figs + >>> np.random.seed(1234) >>> spacing = np.linspace(-9 * np.pi, 9 * np.pi, num=1000) >>> s = pd.Series(0.7 * np.random.rand(1000) + 0.3 * np.sin(spacing)) >>> pd.plotting.autocorrelation_plot(s) # doctest: +SKIP -- 2.30.2